package emulator.hardware.nmos6502.commands;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.CommandSet;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.Operand;
import emulator.hardware.nmos6502.operands.Absolute;
import emulator.hardware.nmos6502.operands.AbsoluteX;
import emulator.hardware.nmos6502.operands.ZeroPage;
import emulator.hardware.nmos6502.operands.ZeroPageX;

/** INC (INCrement memory)
 *  
 *  Affects Flags: S Z
 *  
 *  MODE           SYNTAX       HEX LEN TIM
 *  Zero Page     INC $44       $E6  2   5
 *  Zero Page,X   INC $44,X     $F6  2   6
 *  Absolute      INC $4400     $EE  3   6
 *  Absolute,X    INC $4400,X   $FE  3   7
 */
public class INC implements Command {

	@Override
	public void execute(Cpu6502 cpu, Operand operand) throws EmulatorException {
		HwByte value = operand.getByte();
		value.inc(1);
		operand.setByte(value);
		Flags6502 flags = cpu.getFlags();
		flags.setNZFromValue(value);
		cpu.setFlags(flags);
	}

	@Override
	public String getName() {
		return "INC";
	}

	@Override
	public void register(CommandSet cset) {
		cset.defineCommand(0xE6, this, new ZeroPage(), 4);
		cset.defineCommand(0xF6, this, new ZeroPageX(), 4);
		cset.defineCommand(0xEE, this, new Absolute(), 4);
		cset.defineCommand(0xFE, this, new AbsoluteX(false), 5);
	}

}
